import {useAsync} from "./use-async";
import {Project} from "../screens/projectList/list";
import {useEffect} from "react";
import {cleanObject} from "./index";
import {useHttp} from "./http";

export const useProjects = (param?: Partial<Project>) => {
    const {run, ...result} = useAsync<Project[]>()
    const client = useHttp()
    useEffect(() => {
        run(client("projects", {data: cleanObject(param || {})}))
        //eslint-disable-next-line react-hooks/exhaustive-deps
    }, [param])

    return result
}